package controllers;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import models.Product;
import models.Trade;
import models.TradeProductList;
import play.mvc.Controller;
import util.CheckInfo;

public class TradeController extends Controller {


    public static void newTrade() {
        render();
    }
    
    public static void save(String title, String company, String types, String product, String desc,
			 String price,  String contract, String tel, String email,String area){
    	
		// ----------验证厂商 类型 产品信息  ----------
		Product targetProduct = CheckInfo.saveOrUpdateCompanyTypeProduct(company, types, product);
    	
		Trade trade=new Trade();
		
		trade.title=title;
		trade.depict=desc;
		trade.area=area;
		trade.price=price;
		trade.email=email;
		trade.contract=contract;
		trade.email=email;
		trade.tel=tel;
		trade.available=Trade.AvaiableStatus.in.getStatValue();
		trade.time=new Date();
		Set<TradeProductList> tradeproductlists = new HashSet<TradeProductList>();
		trade.tradeproductlists=tradeproductlists;
		
		trade.save();
		
		TradeProductList TPlist = new TradeProductList();
		TPlist.product = targetProduct;
		TPlist.trade = trade;
		TPlist.save();
		tradeproductlists.add(TPlist);
    	
    	render();
    }
    
    
    /**
     * 出售信息详情
     */
    public static void detail(long typeID){
    	
    	TradeProductList tradeProductList = TradeProductList.detail(typeID);
    	
    	render(tradeProductList);
    	
    }
    
    
}
